/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data.classDiagram;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamImplicit;
import data.stateDiagram.ConditionalTransition;
import data.stateDiagram.State;
import data.stateDiagram.StateDiagram;
import data.stateDiagram.Transition;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@XStreamAlias("class-entity")
public class ClassEntity extends Entity {

    private String baseClass;
    @XStreamImplicit
    private List<Trigger> triggers;
    private StateDiagram stateDiagram;

    public ClassEntity() {
        super();
        baseClass = "";
        stateDiagram = new StateDiagram();
        triggers = new ArrayList<Trigger>();
    }

    public String getBaseClass() {
        return baseClass;
    }

    public void setBaseClass(String baseClass) {
        this.baseClass = baseClass;
    }

    public StateDiagram getStateDiagram() {
        return stateDiagram;
    }

    public void setStateDiagram(StateDiagram stateDiagram) {
        this.stateDiagram = stateDiagram;
    }

    public List<Trigger> getTriggers() {
        return triggers != null ? triggers : Collections.<Trigger>emptyList();
       // return triggers;
    }

    public void addTrigger(Trigger trigger) {
        this.triggers.add(trigger);
    }

    public void removeTrigger(String name) {
        for (Trigger m : triggers) {
            int index = triggers.indexOf(m);
            if (m.getName().equals(name)) {
                triggers.remove(index);
                break;
            }
        }
    }

    @Override
    public void afterUnmarshaling() {
        if (triggers == null) triggers = new ArrayList<Trigger>();

        super.afterUnmarshaling();
    }
}
